package sctu.edu.java.year2016.team06.yuweimei.day20160612.chapter15_3;

import javax.sql.rowset.Joinable;
import javax.swing.*;

/**尝试开发一个窗体，在窗体中设计一个进度条，使进度条每次递增滚动。
 * Created by asus on 2016/6/13.
 */
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JProgressBar;

public class ChuangTi2 extends JFrame {
    private Thread threadA;               //定义线程
    final JProgressBar progressBar = new JProgressBar();             //定义进度条组件
    int count = 0;

    public static void main(String[] args) {
        init(new ChuangTi2(), 100, 100);
    }

    public ChuangTi2() {
        super();
        getContentPane().add(progressBar, BorderLayout.NORTH);             //将进度条设置在窗体最北面
        progressBar.setStringPainted(true);               //使用匿名内部类形式初始化Thread实例
        threadA = new Thread(new Runnable() {
            int count = 0;

            @Override
            public void run() {          //重写run方法
                while (true) {
                    progressBar.setValue(++count);              //设置进度条的当前值
                    try {
                        threadA.sleep(100);//使线程A休眠100毫秒

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        threadA.start();        //启动线程A
    }

    public static void init(JFrame frame, int width, int height) {               //设置窗体各种属性
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(width, height);
        frame.setVisible(true);
    }

}



